package DataOperator;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

public class Builder {
	
	public enum BuildMode{
		ListMode, AllMode
	}
	BuildMode mode;
	BaseImporter importer = null;
	BasePackager packager = null;
	
	public ArrayList<String> words = new ArrayList<String>();
	public HashMap<String, WordBuildInfo> dict = new HashMap<String, WordBuildInfo>();
	
	public Builder(BaseImporter i, BasePackager p, BuildMode m){
		importer = i;
		importer.builder = this;
		packager = p;
		packager.Init();
		packager.builder = this;
		mode = m;
	}
	
	protected int GetBuildSize(){
		return words.size();
	}
	
	private void BuildList() throws IOException{
		for(String word : words){
			WordBuildInfo info = dict.get(word);
			assert(info != null);
			packager.PrepareWord(word, info);
		}
		for(String word : words){
			WordBuildInfo info = dict.get(word);
			assert(info != null);
			packager.BuildWord(word, info);
		}
	}
	
	public void Build() throws IOException{
		importer.Import();
		packager.BeforeBuild();
		BuildList();
		packager.AfterBuild();
	}
}
